<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Spin Border</title>
</head>

<body>
  <div class="container">
    <div class="content"></div>
  </div>

  <script>
    setTimeout(() => {
      const container = document.querySelector(".container");
      const { width, height } = container.getBoundingClientRect();
      const diameter = Math.sqrt(width ** 2 + height ** 2) + 10;
      container.setAttribute("style", `--diameter: ${diameter}px;`);
    });
  </script>

  <style>
    :root {
      --width: 360px;
      --height: 360px;

      background-color: black;
    }

    .container {
      margin: 0 auto;
      width: var(--width);
      height: var(--height);
      overflow: hidden;
      padding: 2px;
      position: relative;
    }

    .container .content {
      width: 100%;
      height: 100%;
      background-color: black;
    }

    .container::before {
      content: '';
      position: absolute;
      left: calc(-0.5 * (var(--diameter) - var(--width)));
      top: calc(-0.5 * (var(--diameter) - var(--height)));
      background-image: linear-gradient(red 0, green);
      width: var(--diameter);
      height: var(--diameter);
      animation: spin 5s linear infinite;
      z-index: -1;
    }

    @keyframes spin {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }

  </style>
</body>

</html>
